import store from '@/store'
function checkPermission(el, binding) {
  let { arg } = binding
  // 小说和游戏的权限控制
  store.state.user.mini_app_id && store.state.user.mini_app_id !== 'undefined' ? '' : arg = 'all-' + arg
  const roles = store.getters && store.getters.buttonInfo
  const hasPermission = Object.prototype.hasOwnProperty.call(roles, arg) ? roles[arg] : false
  if (!hasPermission) {
    el.parentNode && el.parentNode.removeChild(el)
  }
}

export default {
  inserted(el, binding) {
    checkPermission(el, binding)
  },
  update(el, binding) {
    checkPermission(el, binding)
  }
}
